const db = require('../db');
const express = require('express');
const router = express.Router();
//获取用户信息接口
router.get('/userinfo', (req, res) => {
    db('select * from user where id=' +
        req.user.id, (err, resut) => {
            if (err) throw err;
            res.send({
                status: 0,
                message: '获取用户信息成功',
                data: result[0]
            })
        })
});
//更新用户信息接口
router.post('/userinfo', (req, res) => {
    if (req.body.id != req.user.id) {
        return res.send({
            status: 1,
            message: '无权修改'
        })
    }
    let { id, nickname, email } = req.body;
    let sql = `update user set nickname='${nickname}',email='${email}' where id=${id}`;
    db(sql, (err, result) => {
        if (err) throw err;
        res.send({
            status: 0,
            message: '更新用户信息成功'
        });
    });
});
module.exports = router;